package com.ctsi.security.app.controller;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.common.response.UnifiedResponse;
import com.ctsi.framework.security.util.SecurityUtil;
import com.ctsi.security.PermissionSer;
import com.ctsi.security.PermissionTypeSer;
import com.ctsi.security.app.vo.PermissionTypeVO;
import com.ctsi.security.app.vo.PermissionVO;
import com.ctsi.security.domain.Permission;
import com.ctsi.security.domain.PermissionType;
import com.ctsi.security.service.DataObjectTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
public class PermTypeController {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PermTypeController.class);
	@Autowired
	private PermissionTypeSer permissionTypeService;
    @Autowired
	private PermissionSer permissionService;
    @Autowired
	private DataObjectTypeService dataObjectTypeService;

	/** *********************系统资源CRUD***************start************************************ */

    /**
     * 查询系统资源数据
     * @param permissionTypeVO
     * @return
     */
    @PostMapping(value = "/permission/types")
	public UnifiedResponse<Page<PermissionType>> permTypePage(@RequestBody PermissionTypeVO permissionTypeVO) {
		String userLogin = SecurityUtil.getUser().getLoginId();

		Page<PermissionType> page = permissionTypeService.queryPermissionType(userLogin, "sysModule",
                "SELECT", permissionTypeVO.getPermissionId(), permissionTypeVO.getPermissionName(), permissionTypeVO.getPageSize(), permissionTypeVO.getStart());

		return UnifiedResponse.ok(page);
	}

//	// 打开系统资源添加页面
//	public ModelAndView addPermType(HttpServletRequest request, HttpServletResponse response) {
//		return new ModelAndView("security/permType/addPermType");
//	}
//
//	// 保存系统资源
//	public ModelAndView savePermType(HttpServletRequest request, HttpServletResponse response) {
//		/**
//		 * gyz modified at 2008-4-3
//		 */
//		// 增加数据对象类型的保存
//		// 获得数据对象类型ID
//		String dataObjectTypeId = request.getParameter("dataObjectTypeId");
//		// 判断是否为空
//		if (UtilValidate.isNotEmpty(dataObjectTypeId)) {// 不空
//
//			// 持久化到数据库表中
//		} else {// 为空
//			logger.info("{}没有数据对象类型与之相应", request.getParameter("permissionTypeId"));
//		}
//		return this.saveOrUpdatePermType(request, response);
//	}
//
//	// 更新系统资源
//	public ModelAndView updatePermType(HttpServletRequest request, HttpServletResponse response) {
//
//		return this.saveOrUpdatePermType(request, response);
//	}
//
	// 保存系统资源
    @PostMapping(value= "/permissiontype/save")
	public UnifiedResponse<Void> saveOrUpdatePermType(HttpServletRequest request, HttpServletResponse response) {
		String ID = request.getParameter("id");
		String permissionTypeId = request.getParameter("permissionTypeId");
		String permissionTypeName = request.getParameter("permissionTypeName");
		String parentId = request.getParameter("parentId");
		String description = request.getParameter("description");
		ID = ID == null ? "" : ID.trim();
		permissionTypeId = permissionTypeId == null ? "" : permissionTypeId.trim();
		permissionTypeName = permissionTypeName == null ? "" : permissionTypeName.trim();
		parentId = parentId == null || parentId.equals("") ? "0" : parentId.trim();

		description = description == null ? "" : description.trim();
		PermissionType permType = new PermissionType();
		permType.setId(ID);
		permType.setPermissionTypeId(permissionTypeId);
		permType.setPermissionTypeName(permissionTypeName);
		permType.setParentId(parentId);
		permType.setDescription(description);
		String dataObjectId = request.getParameter("dataObjectId");
		/**
		 * gyz modified at 2008-4-3
		 */
		// 增加或更新该功能类型的数据对象Id
		// 获得数据对象类型Id
//		String dataObjectId = getDataObjectParamValue("saveOrUpdatePermType", request);
		// 判断是否为空
		if (UtilValidate.isEmpty(dataObjectId)) {
			// 为空
			logger.info("{}对应的数据对象Id为空", permissionTypeId);
		} else {
			logger.info("{}对应的数据对象Id为{}", permissionTypeId, dataObjectId);
			permType.setDataObject(dataObjectId);
		}
		if (UtilValidate.isEmpty(ID)) {// 新增
			if (permissionTypeService.valPermTypeId(permissionTypeId)) {
				return UnifiedResponse.error("-1", "数据库中已存在该ID,请重新填写");
			} else {
				permissionTypeService.savePermissionType(permType);
			}
		} else {// 更新
			permissionTypeService.updatePermissionType(permType);
		}
		return UnifiedResponse.ok();
	}
//
//	// 打开修改页面
//	public ModelAndView editPermType(HttpServletRequest request, HttpServletResponse response) {
//		String ID = request.getParameter("ID");
//		/**
//		 * 增加接收功能类型参数gyz modified at 2008-4-7
//		 */
//		// 类型Id
//		String typeId = request.getParameter("typeId");
//
//		ID = ID == null ? "" : ID;
//		String parentId = "";
//		String parentName = "";
//		PermissionType permType = null;
//		List<PermissionType> listPermType;
//		// 如果没有接收到ID参数,只接收到typeId参数
//		if (ID.equals("") && UtilValidate.isNotEmpty(typeId)) {// 接收到typeId参数
//			listPermType = permissionTypeService.findPermissionType(new String[] { "permissionTypeId" }, new Object[] { typeId });
//			logger.debug("按照类型Id查询");
//
//		} else {// 接收到ID参数
//			listPermType = permissionTypeService.findPermissionType(new String[] { "ID" }, new Object[] { ID });
//			logger.debug("按照ID查询");
//		}
//		if (listPermType.size() > 0) {
//			permType = listPermType.get(0);
//			parentId = permType.getParentId();
//			List<PermissionType> listParent = permissionTypeService.findPermissionType(new String[] { "permissionTypeId" }, new Object[] { parentId });
//			if (listParent.size() > 0) {
//				parentName = listParent.get(0).getPermissionTypeName();
//			}
//		} else {
//			permType = new PermissionType();
//		}
//
//		request.setAttribute("permType", permType);
//		request.setAttribute("parentName", parentName);
//		return new ModelAndView("security/permType/editPermType");
//	}

	/**
	 * 获取编辑得权限类型
	 *
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/permission/types/{id}")
	public UnifiedResponse<PermissionType> editPermType(@PathVariable(value = "id") String id){
		List<PermissionType> listPermType = permissionTypeService.findPermissionType(new String[] { "ID" }, new Object[] { id });
		//TODO： 处理细节
		return UnifiedResponse.ok(listPermType.get(0));
	}

//

	/**
	 * 删除资源类型 1
 	 * @param ids
	 * @param permissionTypeIds
	 * @return
	 */
	@DeleteMapping(value = "/permission-type/delete")
	public UnifiedResponse<Void> delPermType(@RequestParam(value = "ids") String ids,@RequestParam(value = "permissionTypeIds") String permissionTypeIds) {
		String[] arrayId = ids.split(",");
		String[] arrayPermTypeId = permissionTypeIds.split(",");
		int[] ret = { -1, -1 };
		try {
			ret = permissionTypeService.removePermissionType(arrayId, arrayPermTypeId);
			if (ret[0] > -1)
				throw new Exception("功能类型" + arrayPermTypeId[ret[0]] + "下有系统功能");
			if (ret[1] > -1)
				throw new Exception("功能类型" + arrayPermTypeId[ret[1]] + "下有子功能类型");
		} catch (Exception e) {
			if (ret[0] > -1) {
				return UnifiedResponse.error("-1","功能类型" + arrayPermTypeId[ret[0]] + "下有系统功能,不能删除");
			}
			if (ret[1] > -1) {
				return UnifiedResponse.error("-1","功能类型" + arrayPermTypeId[ret[1]] + "下有子功能类型,不能删除");
			}
		}
		return UnifiedResponse.ok();
	}
//
//	// 显示某资源下的功能列表
//	public ModelAndView viewPermTypePerm(HttpServletRequest request, HttpServletResponse response) {
//		String permTypeId = request.getParameter("permTypeId");
//		String permTypeName = "";
//
//		List<PermissionType> listPermissionType = new ArrayList<PermissionType>(0);
//		String typeId = request.getParameter("typeId");
//		if (UtilValidate.isNotEmpty(typeId)) {
//			// 传递的类型的无意义Id
//			listPermissionType = permissionTypeService.findPermissionType(new String[] { "id" }, new Object[] { typeId });
//		} else {
//			// 传递的类型的ID
//			listPermissionType = permissionTypeService.findPermissionType(new String[] { "permissionTypeId" }, new Object[] { permTypeId });
//		}
//		if (listPermissionType.size() > 0) {
//			permTypeId = listPermissionType.get(0).getPermissionTypeId();
//			permTypeName = listPermissionType.get(0).getPermissionTypeName();
//		}
//		request.setAttribute("permTypeId", permTypeId);
//		request.setAttribute("permTypeName", permTypeName);
//		return new ModelAndView("security/permType/permTypePerm");
//	}

    /**
     * 查询某资源下的功能 1
     * @param permissionVO
     * @return
     */
    @PostMapping(value = "/permission/permissions")
	public UnifiedResponse<Page<Permission>> permTypePermPage(@RequestBody PermissionVO permissionVO) {

        String userLogin = SecurityUtil.getUser().getLoginId();// 当前登录用户

        Page<Permission> page;
        if (permissionVO.isWild()) {
            // 不局限于某一数据对象类型，全局查询
            logger.debug("全局查询");
            page = permissionService.queryPermission(userLogin, "sysModule", "SELECT", permissionVO.getPermissionId(),
                    permissionVO.getPermissionName(), permissionVO.getPtype(), permissionVO.getPageSize(), permissionVO.getStart(), null);
        } else {// 局限于某一数据对象类型
            logger.debug("局限于{}内查询", permissionVO.getPermTypeId());
            page = permissionService.queryPermission(userLogin, "sysModule", "SELECT", permissionVO.getPermissionId(), permissionVO.getPermissionName(),
                    permissionVO.getPtype(), permissionVO.getPageSize(), permissionVO.getStart(), permissionVO.getPermTypeId());
//			PermissionType permType = permissionTypeService.findByPermisionTypeId(permissionVO.getPermTypeId());
//			String permTypeName = "";
//			if (permType!=null) {
//				permTypeName = permType.getPermissionTypeName();
//			}
        }
        return UnifiedResponse.ok(page);
    }
//		/*
//		 * 修改结束
//		 */
//		preJson(request, "permTypeInfo", page.getResult(), "id", "permissionId");
//		PageUtil<Permission> out = new PageUtil<Permission>(page);
//		super.outJson(out, response);
//		return null;
//	}
//
//	public ModelAndView permTypeInfo(HttpServletRequest request, HttpServletResponse response) {
//		String dataId = request.getParameter("dataid");
//
//		String userLogin = getHandleUserLogin().getLoginUserId(request);
//
//		if (UtilValidate.isNotEmpty(dataId)) {
//			// 对DataId进行Base64解码
//			dataId = InfoEngine.getInfoEngine().decode(dataId);
//			Permission permission = new Permission();
//			Map<String, Object> map = new HashMap<String, Object>();
//			map.put("id", dataId);
//			List<Permission> permissionlist = permissionService.findPermission(userLogin, "sysModule", "SELECT", map);
//			if (UtilValidate.isNotEmpty(permissionlist)) {
//				permission = (Permission) permissionlist.get(0);
//			}
//			List<SRole> list = permissionService.getSRoleByPartyId(userLogin, "sysModule", "SELECT", permission.getPermissionId());
//
//			request.setAttribute("permission", permission);
//			request.setAttribute("srole", list);
//		}
//
//		return new ModelAndView("security/permType/permTypeInfo");
//	}
//
//	// 打开特定资源下资源添加功能
//	public ModelAndView addPermTypePerm(HttpServletRequest request, HttpServletResponse response) {
//		String permTypeId = request.getParameter("permTypeId");
//		permTypeId = permTypeId == null ? "" : permTypeId;
//		request.setAttribute("permTypeId", permTypeId);
//		return new ModelAndView("security/permType/addPermTypePerm");
//	}
//
//	// 保存特定资源下的数据功能
//	public ModelAndView savePermTypePerm(HttpServletRequest request, HttpServletResponse response) {
//		return this.saveOrUpdatePermTypePerm(request, response);
//	}
//
//	// 更新特定资源下的数据功能
//	public ModelAndView updatePermTypePerm(HttpServletRequest request, HttpServletResponse response) {
//		return this.saveOrUpdatePermTypePerm(request, response);
//	}
//

    /**
     *
     * @param request
     * @param response
     * @return
     */
    @PostMapping(value = "/permission/save")
	public UnifiedResponse<Void> saveOrUpdatePermTypePerm(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("ID");
		id = id == null ? "" : id;
		String permissionId = request.getParameter("permissionId");
		permissionId = permissionId == null ? "" : permissionId.trim();
		String permissionAction = request.getParameter("permissionAction");
		permissionAction = permissionAction == null ? "" : permissionAction.trim();
		permissionId = !permissionAction.equals("") ? permissionId + "-" + permissionAction : permissionId;
		String permissionName = request.getParameter("permissionName");
		permissionName = permissionName == null ? "" : permissionName.trim();
		String permissionTypeId = request.getParameter("permissionTypeId");
		permissionTypeId = permissionTypeId == null ? "" : permissionTypeId.trim();
		String objectDataId = request.getParameter("objectDataId");
		objectDataId = objectDataId == null ? "" : objectDataId.trim();
		String description = request.getParameter("description");
		description = description == null ? "" : description.trim();
		String pType = request.getParameter("pType");
		pType = pType ==null ? "" : pType.trim();
		Permission permission = new Permission();
		permission.setId(id);
		permission.setPermissionId(permissionId);
		permission.setPermissionName(permissionName);
		permission.setPermissionTypeId(permissionTypeId);
		permission.setDataObject(objectDataId);
		permission.setDescription(description);
		permission.setpType(pType);
		PermissionType permissionType = permissionTypeService.findByPermisionTypeId(permissionTypeId);
		String permTypeName = "";
		if(permissionType!=null){
			permTypeName = permissionType.getPermissionTypeName();
		}
		if (id.equals("")) {
			if (permissionService.valPermissionId(permissionId)) {
				return UnifiedResponse.error("-1", "数据库中已存在该ID，请重新填写!");
			} else {
				permissionService.savePermission(permission);
			}
		} else {
			permissionService.updatePermission(permission);
		}
		return UnifiedResponse.ok();

	}
//
//	// 打开修改页面
//	public ModelAndView editPermTypePerm(HttpServletRequest request, HttpServletResponse response) {
//		String ID = request.getParameter("ID");
//		ID = ID == null ? "" : ID;
//		Permission permission = null;
//		List<Permission> listPermission = permissionService.findPermission(new String[] { "ID" }, new Object[] { ID });
//		if (listPermission.size() > 0) {
//			permission = listPermission.get(0);
//		} else {
//			permission = new Permission();
//		}
//		request.setAttribute("permission", permission);
//		return new ModelAndView("security/permType/editPermTypePerm");
//	}
//

	/**
	 * 删除资源类型功能
	 * @param ids
	 * @param permissionIds
	 * @return
	 */
	@DeleteMapping(value = "/permission/delete")
	public UnifiedResponse<Void> delPermTypePerm(@RequestParam(value = "ids") String ids, @RequestParam(value = "permissionIds") String permissionIds) {
		String[] arrayId = ids.split(",");
		String[] arrayPermissionId = permissionIds.split(",");
		for (int i = 0; i < arrayId.length; i++) {
			permissionService.removePermission(arrayId[i], arrayPermissionId[i]);
		}
		return UnifiedResponse.ok();
	}
//
//	/**
//	 * 功能类型查看
//	 *
//	 * @param request
//	 * @param response
//	 * @return
//	 */
//	public ModelAndView typePermIndex(HttpServletRequest request, HttpServletResponse response) {
//		return new ModelAndView("security/permType/permTypeIndex");
//	}
//
//	/**
//	 * 功能类型编辑
//	 *
//	 * @param request
//	 * @param response
//	 * @return
//	 */
//	public ModelAndView typePermEditIndex(HttpServletRequest request, HttpServletResponse response) {
//		return new ModelAndView("security/permType/permTypeEditIndex");
//	}
//
//	/** *********************系统资源CRUD***************end************************************ */
//	/** *********************资源下对象类型管理**********start********************************** */
//
//	/** *********************资源下对象类型管理**********end *************************************/
//
//	/************************* 子菜单功能类型树***************start ***********************************/
//	public ModelAndView permTypeTree(HttpServletRequest request, HttpServletResponse response) {
//		String parentId = request.getParameter("parentId");
//		parentId = parentId == null ? "root" : parentId.trim();
//		// 用于控制数据权限
//		String userLoginId = getHandleUserLogin().getLoginUserId(request);// 当前登录用户
//
//		StringBuilder sb = new StringBuilder("[");
//		if (parentId.equals("root")) {
//			// List<PermissionType> listPermType=permissionTypeService.findAllSon("0");
//			List<PermissionType> listPermType = permissionTypeService.findAllSon(userLoginId, "sysModule", "SELECT", "0");
//			String leafValue = "true";
//			if (listPermType.size() > 0) {
//				leafValue = "false";
//			}
//			sb.append("{\"id\":\"0\",\"value\":\"root\",\"text\":\"功能类型列表\",\"leaf\":" + leafValue + ",\"children\": [");
//			for (PermissionType permType : listPermType) {
//				String localLeafValue = "true";
//				String url = "";
//				List<PermissionType> localListPermType = permissionTypeService.findAllSon(permType.getPermissionTypeId());
//				if (localListPermType.size() > 0) {
//					localLeafValue = "false";
//				}
//				//zhangjw 2015-3-16
//				// else {
//					url = ",\"url\":\"/permtype/viewPermTypePerm.do?typeId=" + permType.getId() + "\",\"href\":\"/permtype/viewPermTypePerm.do?permTypeId=" + permType.getPermissionTypeId() + "\"";
//				//}
//				sb.append("{\"id\":\"" + permType.getId() + "\",\"value\":\"" + jsonEncoding(permType.getPermissionTypeId()) + "\",\"text\":\"" + jsonEncoding(permType.getPermissionTypeName()) + "\",\"leaf\":" + localLeafValue + " " + url + " },");
//
//			}
//			if (sb.indexOf(",") != -1) {// 删除最后一个逗号
//				sb.deleteCharAt(sb.length() - 1);
//			}
//			sb.append("],\"expanded\":true}");
//			/**
//			 * gyz modified at 2008-3-31
//			 */
//			// String rootUrl=",url:'/permtype/viewPermType.do',href:'/permtype/viewPermType.do' ";
//			// rootUrl=",url:'/permtype/viewTypeTree.do'";
//			// String rootUrl=",url:'".concat(request.getContextPath()).concat("/permtype/viewTypeTree.do'");
//			// sb.append(",{id:'permtype',value:'permtype',text:'查看功能类型',leaf:true "+rootUrl).append(",listeners:{click:function(){activate(this);loadURL('permType','/permtype/viewPermType.do','功能类型');}}}");
//			/**
//			 * gyz modified at 2008-3-31
//			 */
//		} else {
//			List<PermissionType> listPermType = permissionTypeService.findAllSon(userLoginId, "sysModule", "SELECT", parentId);
//			PermissionType permissionType = permissionTypeService.findByPermisionTypeId(parentId);
//			String permTypeName = "";
//			if(permissionType!=null){
//				permTypeName = permissionType.getPermissionTypeName();
//			}
//			for (PermissionType permType : listPermType) {
//				String localLeafValue = "true";
//				List<PermissionType> localListPermType = permissionTypeService.findAllSon(permType.getPermissionTypeId());
//				String url = "";
//				if (localListPermType.size() > 0) {
//					localLeafValue = "false";
//				} else {
//					url = ",\"url\":\"/permtype/viewPermTypePerm.do?typeId=" + permType.getId() + "\",\"href\":\"/permtype/viewPermTypePerm.do?permTypeId=" + permType.getPermissionTypeId() + "\"";
//				}
//				sb.append("{\"id\":\"" + permType.getId() + "\",\"value\":\"" + jsonEncoding(permType.getPermissionTypeId()) + "\",\"text\":\"" + jsonEncoding(permType.getPermissionTypeName()) + "\",\"leaf\":" + localLeafValue + " " + url + "},");
//			}
//			sb.deleteCharAt(sb.length() - 1);
//		}
//		sb.append("]");
//		logger.info("The Json is {}", sb);
//		outJson(sb.toString(), response);
//		return null;
//	}
//
//	/************************* 功能类型树***************end *************************************/
//
//	/**
//	 * 功能类型树2（gyz added at 2008-3-31）
//	 *
//	 * @param request
//	 * @param response
//	 * @return
//	 */
//	/**
//	 * @param request
//	 * @param response
//	 * @return
//	 */
//	public ModelAndView viewTypeTree(HttpServletRequest request, HttpServletResponse response) {
//		// 更改上面的功能类型树，把URL变为编辑页面
//		String parentId = request.getParameter("parentId");
//		parentId = parentId == null ? "root" : parentId.trim();
//		// 用于控制数据权限
//		String userLoginId = getHandleUserLogin().getLoginUserId(request);// 当前登录用户
//
//		StringBuilder sb = new StringBuilder("[");
//		List<Map<String,Object>> lists=new ArrayList<>();
//		Map<String,Object> maps=new HashMap<>();
//		Map<String,Object> maps2=new HashMap<>();
//		// 为非叶子节点加上超链接，方便非叶子节点的功能类型编辑
//		if (parentId.equals("root")) {
//			List<PermissionType> listPermType = permissionTypeService.findAllSon(userLoginId, "sysModule", "SELECT", "0");
//			boolean leafValue = true;
//			if (listPermType.size() > 0) {
//				leafValue = false;
//			}
//			maps.put("id","0");
//			maps.put("value","root");
//			maps.put("text","功能类型列表");
//			maps.put("leaf",leafValue);
//			List<Map<String,Object>> list=new ArrayList<>();
//			sb.append("{\"id\":\"0\",\"value\":\"root\",\"text\":\"功能类型列表\",\"leaf\":" + leafValue + ",\"children\": [");
//			for (PermissionType permType : listPermType) {
//				Map<String,Object> map=new HashMap<>();
//				boolean localLeafValue = true;
//				String url = "";
//				List<PermissionType> localListPermType = permissionTypeService.findAllSon(permType.getPermissionTypeId());
//				if (localListPermType.size() > 0) {// 非叶子节点
//					localLeafValue = false;
//					// 为非叶子节点加上listener,在右边Tab页中打开
//					url=",url:'/permtype/editPermType.do?ID="+jsonEncoding(permType.getId())+"',href:'/permtype/editPermType.do?ID="+jsonEncoding(permType.getId())+"'";
//					//url = ",\"listeners\":{click:function(){loadURL(\"permType\",\"/permtype/editPermType.do?ID=" + jsonEncoding(permType.getId()) + "\",\"功能类型\");}}";
//				} else {
//					//url = ",\"listeners\":{click:function(){loadURL(\"permType\",\"/permtype/editPermType.do?ID=" + jsonEncoding(permType.getId()) + "\",\"功能类型\");}}";
//					 url=",url:'/permtype/editPermType.do?ID="+jsonEncoding(permType.getId())+"',href:'/permtype/editPermType.do?ID="+jsonEncoding(permType.getId())+"'";
//				}
//				map.put("id",permType.getId());
//				map.put("value",jsonEncoding(permType.getPermissionTypeId()));
//				map.put("text",jsonEncoding(permType.getPermissionTypeName()));
//				map.put("leaf",localLeafValue);
//				map.put("url", "/permtype/editPermType.do?ID="+jsonEncoding(permType.getId()));
//				map.put("href", "/permtype/editPermType.do?ID="+jsonEncoding(permType.getId()));
//				list.add(map);
//				sb.append("{\"id\":\"" + permType.getId() + "\",\"value\":\"" + jsonEncoding(permType.getPermissionTypeId()) + "\",\"text\":\"" + jsonEncoding(permType.getPermissionTypeName()) + "\",\"leaf\":" + localLeafValue + " " + url + " },");
//			}
//			sb.deleteCharAt(sb.length() - 1);
//			sb.append("],\"expanded\":true}");
//			maps.put("children", list);
//			maps.put("expanded", true);
//			lists.add(maps);
//			/**
//			 * 增加返回功能类型列表
//			 */
//			// String rootUrl=",url:'".concat(request.getContextPath()).concat("/permtype/viewTypeTree.do'");
//			// 需要active(this);
//			maps2.put("id", "permtype");
//			maps2.put("value","permtype" );
//			maps2.put("text","查看功能类型列表" );
//			maps2.put("leaf",true);
//			maps2.put("value","permtype" );
//			maps2.put("url", "/permtype/viewPermType.do");
//			maps2.put("href", "/permtype/viewPermType.do");
//			lists.add(maps2);
//			//sb.append(",{\"id\":\"permtype\",\"value\":\"permtype\",\"text\":\"查看功能类型列表\",\"leaf\":true ").append(",\"listeners\":{click:function(){loadURL(\"permType\",\"/permtype/viewPermType.do\",\"功能类型\");}}}");
//
//
//		} else {
//			List<PermissionType> listPermType = permissionTypeService.findAllSon(userLoginId, "sysModule", "SELECT", parentId);
//			for (PermissionType permType : listPermType) {
//				Map<String,Object> map=new HashMap<>();
//				boolean localLeafValue = true;
//				List<PermissionType> localListPermType = permissionTypeService.findAllSon(permType.getPermissionTypeId());
//				String url = "";
//				if (localListPermType.size() > 0) {// 非叶子节点
//					localLeafValue = false;
//					// 为非叶子节点加上listener,在右边Tab页中打开
//					url=",url:'/permtype/editPermType.do?ID="+jsonEncoding(permType.getId())+"',href:'/permtype/editPermType.do?ID="+jsonEncoding(permType.getId())+"'";
//					//url = ",\"listeners\":{click:function(){loadURL(\"permType\",\"/permtype/editPermType.do?ID=" + jsonEncoding(permType.getId()) + "\",\"功能类型\");}}";
//				} else {
//					//url = ",\"listeners\":{click:function(){loadURL(\"permType\",\"/permtype/editPermType.do?ID=" + jsonEncoding(permType.getId()) + "\",\"功能类型\");}}";
//					 //url=",url:'/permtype/editPermType.do?ID="+jsonEncoding(permType.getId())+"',href:'/permtype/editPermType.do?ID="+jsonEncoding(permType.getId())+"'";
//					url="/permtype/editPermType.do?ID="+jsonEncoding(permType.getId());
//				}
//				map.put("id",permType.getId());
//				map.put("value",jsonEncoding(permType.getPermissionTypeId()));
//				map.put("text",jsonEncoding(permType.getPermissionTypeName()));
//				map.put("leaf",localLeafValue);
//				map.put("url", url);
//				lists.add(map);
//				sb.append("{\"id\":\"" + permType.getId() + "\",\"value\":\"" + jsonEncoding(permType.getPermissionTypeId()) + "\",\"text\":\"" + jsonEncoding(permType.getPermissionTypeName()) + "\",\"leaf\":" + localLeafValue + " " + url + "},");
//			}
//
//			sb.deleteCharAt(sb.length() - 1);
//		}
//		sb.append(']');
//		outJson(lists, response);
//		return null;
//	}
//
//	public void setPermissionTypeService(PermissionTypeSer permissionTypeService) {
//		this.permissionTypeService = permissionTypeService;
//	}
//
//	public void setPermissionService(PermissionSer permissionService) {
//		this.permissionService = permissionService;
//	}
//
//	public DataObjectTypeService getDataObjectTypeService() {
//		return dataObjectTypeService;
//	}
//
//	public void setDataObjectTypeService(DataObjectTypeService dataObjectTypeService) {
//		this.dataObjectTypeService = dataObjectTypeService;
//	}
//
//	private String jsonEncoding(String source) {
//		return JsonUtil.jsonEncoding(source).replace("'", "&#039;");
//	}
//
//	public ModelAndView validatePermssionTypeId(HttpServletRequest request, HttpServletResponse response) {
//		StringBuilder sb = new StringBuilder();
//		String nPermTypeId = request.getParameter("newPermissionTypeId");
//		PermissionType permtype = this.permissionTypeService.findByPermisionTypeId(nPermTypeId);
//		if (null != permtype) {
//			sb.append("{\n \"success\": \"false\",\"result\":\"该ID已存在！！\"}");
//			super.outJson(sb.toString(), response);
//			return null;
//		}
//		sb.append("{\n \"success\": \"true\",\"result\":\"正确！！\"}");
//		super.outJson(sb.toString(), response);
//		return null;
//	}
}
